import { ui, locales, defaultlocale } from './config';

export function getLangFromUrl(url: URL) {
  const [, lang] = url.pathname.split('/');
  if (lang in locales) return lang as keyof typeof locales;
  return defaultlocale;
}


export function useTranslations(lang: keyof typeof ui) {
  return function t(key: keyof typeof ui[typeof defaultlocale]) {
    return ui[lang][key] || ui[defaultlocale][key];
  }
}